# Maintainer: Antoine Lambert <antoine.lambert@inria.fr>

_realname=tulip
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.5.1
pkgrel=3
pkgdesc="Large graphs analysis, drawing and visualization framework (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://tulip.labri.fr/"
license=('LGPL')
options=('strip' 'staticlibs')
source=("https://sourceforge.net/projects/auber/files/tulip/${_realname}-${pkgver}/${_realname}-${pkgver}_src.tar.gz"
        "001-fix-tulip-python-install.patch"
        "002-fix-template-instatiation.patch"
        "003-fix-clang-omp-link.patch"
        "004-fix-tulip-core-headers.patch"
        "005-fix-cmakelists.patch")
sha256sums=('afd4b2052a9d33198d8e4a0a717474511b1f06e26b9a3eac2ac8c8f12af0b4c3'
            '87f788a27483d15cbb0c7c3a9fd8e9a222207584ff1a4990bdc2905c19845f39'
            'bb8ac180f4b6229537244ca70316c42e437667811bc33f5bd8aaa8a2cff8596d'
            '20bc5ed1744505ab89a4aec597e5286451d37c49241b8a784e0a51957f43dc7b'
            'dd7a758bf6e78558a7e94567728fb20fd96c5bdc6bf0481b1943407b31a6b233'
            '32193596196c0eda8a2989bd4467a22c7daf3eaaba3d51d88f0de11b50ba543d')
depends=("${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-glew"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-qhull"
         "${MINGW_PACKAGE_PREFIX}-qt5-base"
         "${MINGW_PACKAGE_PREFIX}-qt5-xmlpatterns"
         "${MINGW_PACKAGE_PREFIX}-qtwebkit"
         "${MINGW_PACKAGE_PREFIX}-quazip"
         "${MINGW_PACKAGE_PREFIX}-yajl")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-sip"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-qt5-tools")

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/001-fix-tulip-python-install.patch
  patch -p1 -i ${srcdir}/002-fix-template-instatiation.patch
  patch -p1 -i ${srcdir}/003-fix-clang-omp-link.patch
  patch -p1 -i ${srcdir}/004-fix-tulip-core-headers.patch
  patch -p1 -i ${srcdir}/005-fix-cmakelists.patch
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_NEED_RESPONSE=ON \
    -DCMAKE_SYSTEM_IGNORE_PATH=/usr/lib \
    -DTULIP_FIXUP_BUNDLE=OFF \
    -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python3.exe \
    -DTULIP_PYTHON_SITE_INSTALL=ON \
    ../${_realname}-${pkgver}

  cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR=${pkgdir} cmake --install .
}
